home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 76 / XENIATGM66.iso / Indiana Jones / Indiana Jones.exe / RESOURCE / PREVIEW.GOB / cog_pru_stairpit2.cog < prev    next >
Text File  |  1999-11-15  |  12KB  |  444 lines

  1. # Jones 3D Cog Script
  2. #
  3. # PRU_stairpit.cog
  4. # Blocks will push you into the pit if you aren't careful.  They also form a stairway out. 
  5. # [GGJ] [PKM]
  6. #
  7. # (C) 1998 LucasArts Entertainment Co. All Rights Reserved
  8. # ========================================================================================
  9.  
  10. symbols
  11.     message entered
  12.     message pulse
  13.     message    arrived
  14.     message    timer
  15.     message touched
  16.     message    exited
  17.     message    startup
  18.     message    blocked
  19.  
  20.     thing   block0
  21.     thing   block1          
  22.     thing   block2
  23.     thing   block3        mask=0x409
  24.     thing   block4        mask=0x409
  25.     thing   block5        mask=0x409
  26.     #thing   block6
  27.     
  28.     thing    fakeBlock0
  29.     thing    fakeBlock1
  30.     thing    fakeBlock2
  31.     thing    fakeBlock3
  32.     thing    fakeBlock4
  33.     thing    fakeBlock5
  34.     #thing    fakeBlock6
  35.     
  36.     thing    blockGhost0
  37.     thing    blockGhost1
  38.     thing    blockGhost2
  39.     thing    blockGhost3
  40.     thing    blockGhost4
  41.     thing    blockGhost5
  42.     #thing    blockGhost6
  43.     
  44.     thing    backGhost0
  45.     thing    backGhost1
  46.     thing    backGhost2
  47.     thing    backGhost3
  48.     thing    backGhost4
  49.     thing    backGhost5
  50.     #thing    backGhost6
  51.     
  52.     thing    player                local
  53.     
  54.     float   moveSpeed=4.0            // How long it takes to push out (was) how fast the blocks push out
  55.     float    retractSpeed=0.5         //how fast they retrack if you jump back the way you came
  56.     float    autoRetractSpeed=3.0    //how fast they retrack automatically, after they're all out
  57.     float   pulseTime=3.0            //after a block starts pushing out, pause before next one starts
  58.     float    autoRetract=10.0        //delay before blocks start retracting automatically
  59.         
  60.     int     counter=0            local
  61.     int        retractCounter=5    local
  62.     int     crosscheck=0         local
  63.     int        out=0                local
  64.     
  65.     
  66.     flex    f_XDist                local
  67.     flex    f_YDist                local
  68.     flex    f_ZDist                local
  69.     thing    invisiBox=-1        local          mask=0x080
  70.     vector    v_modvec            local
  71.     vector    v_targetpos            local
  72.     sector    targetsector        local
  73.     
  74.     template    boxTpl        #currently set in Marcus to "1M oil drum c," will be changed to "1M aimable invisible cube."                             
  75.     
  76.     surface    hangR0        linkID=1    #with your back to the wall these hang ledges are to your right
  77.     surface    hangR1        linkID=1
  78.     surface    hangR2        linkID=1
  79.     surface    hangR3        linkID=1
  80.     surface    hangR4        linkID=1
  81.     
  82.     surface    hangL0        linkID=1    #with your back to the wall these hang ledges are to your left
  83.     surface    hangL1        linkID=1
  84.     surface    hangL2        linkID=1
  85.     surface    hangL3        linkID=1
  86.     surface    hangL4        linkID=1
  87.     surface    hangL5        linkID=1
  88.     
  89.     surface    hangE0        linkID=1
  90.     surface    hangE1        linkID=1
  91.     surface    hangE2        linkID=1
  92.     surface    hangE3        linkID=1
  93.     surface    hangE4        linkID=1
  94.     surface    hangE5        linkID=1
  95.     #surface    hangE6        linkID=1
  96.     
  97.     surface    musTrigger
  98.  
  99.     flex hangDistR0=0.5            local
  100.     flex hangDistR1=0.4            local
  101.     flex hangDistR2=0.3            local
  102.     flex hangDistR3=0.2            local
  103.     flex hangDistR4=0.1            local
  104.  
  105.     flex hangDistL0=-0.6        local
  106.     flex hangDistL1=-0.5        local
  107.     flex hangDistL2=-0.4        local
  108.     flex hangDistL3=-0.3        local
  109.     flex hangDistL4=-0.2        local
  110.     flex hangDistL5=-0.1        local
  111.  
  112.     int currentBlock        local
  113.     int currentSurface        local
  114.     int    bSurfaceFound        local
  115.     int    hanging=0            local
  116.     
  117.     int    bBlockFound=0        local
  118.     int out0=0                local
  119.     int out1=0                local
  120.     int out2=0                local
  121.     int out3=0                local
  122.     int out4=0                local
  123.     int out5=0                local
  124.     int out6=0                local
  125.     int    musOnce=0            local
  126.     
  127.     surface triggerface     mask=0x405
  128.     surface    retractface        mask=0x405
  129.     
  130.     sound    blocksnd=olv_quetzdoor_move_c.wav    local        #fol_in_scrapehard_long.wav      local
  131.     sound    musStairpit=mus_gen_awechord1.wav    local
  132. end
  133. # ========================================================================================
  134. code
  135.  
  136. startup:
  137.  
  138.     player = GetLocalPlayerThing();
  139.  
  140.     # When the blocks are in the wall, they should be "fakeblocks" so that Indy can't hang from them.
  141.     for (currentBlock = 0; (currentBlock <= 5); currentBlock = currentBlock + 1)
  142.     {
  143.         SetThingFlags(block0[currentBlock], 0x80000);
  144.     }
  145.     #SetCollideType(block5, 3);
  146.     #SetCollideType(block4, 3);
  147.     #SetCollideType(block3, 3);
  148.  
  149.  
  150.     return;
  151.  
  152. # ========================================================================================
  153. entered:
  154.  
  155.     # We only care about entered messages from surfaces.
  156.     if (GetSenderType() != 6) return;
  157.  
  158.     if ((GetSenderRef() == musTrigger) && (musOnce == 0))
  159.     {
  160.         musOnce = 1;
  161.         PlaySoundLocal(musStairpit, 1.0, 0.0, 0x0, 0);
  162.     }
  163.     
  164.     # Indy lands on the second platform.
  165.     if ((GetSenderRef() == triggerface) && (crosscheck == 0))
  166.     {
  167.         crosscheck = 1;
  168.  
  169.         # Remove the fake block and add blocks you can hang from.
  170.         SetThingFlags(fakeBlock0[0], 0x80000);
  171.         ClearThingFlags(block0[0], 0x80000);
  172.  
  173.         # The first block starts to move, and the pulse will trigger the rest.
  174.         MoveThingtoPos(block0, GetThingPos(blockGhost0), movespeed);
  175.         out0[0] = 0;
  176.         #PlaySoundThing(blocksnd, block0, 1.0, 7.5, 30.0, 0);
  177.         SetPulse(pulseTime);
  178.         return;
  179.     }
  180.         
  181.     # If Indy jumps back to the entrance
  182.     if ((GetSenderRef() == retractface) && (crosscheck == 1))
  183.     {
  184.         
  185.         Print("entered retract trigger-surface");
  186.         # Shut off the pulse.
  187.         SetPulse(0);
  188.         counter = 0;
  189.         crosscheck = 0;
  190.         retractCounter = 5;
  191.         
  192.         # Move the blocks back.
  193.         for (currentBlock = 0; (currentBlock <= 6); currentBlock = currentBlock + 1)
  194.         {
  195.             MoveThingToPos(block0[currentBlock], GetThingPos(backGhost0[currentBlock]), retractSpeed);
  196.             out0[currentBlock] = 1;
  197.         }
  198.         return;
  199.     }
  200.  
  201.     # Code below checks to see if Indy is hanging from a platform at the base of one of the blocks.
  202.  
  203.     f_YDist = 0.1; # plug in y value here
  204.     f_ZDist = 0.25; # plug in z value here            #changed from 3 for benefit of smallest block
  205.  
  206.     bSurfaceFound = 0;
  207.  
  208.     for (currentSurface = 0; (currentSurface < 5) && !bSurfaceFound; currentSurface = currentSurface + 1)
  209.     {
  210.         // Check to see if we're hanging off the left edge of our block surfaces.
  211.  
  212.         if (GetSenderRef() == hangR0[currentSurface])
  213.         {
  214.             f_XDist = hangDistR0[currentSurface];
  215.             bSurfaceFound = 1;
  216.         }
  217.     }
  218.  
  219.     if (!bSurfaceFound)
  220.     {
  221.         // We're not hanging off the right side - check for the left side.
  222.  
  223.         for (currentSurface = 0; (currentSurface < 6) && !bSurfaceFound; currentSurface = currentSurface + 1)
  224.         {
  225.             if (GetSenderRef() == hangL0[currentSurface])
  226.             {
  227.                 f_XDist = hangDistL0[currentSurface];
  228.                 bSurfaceFound = 1;
  229.             }
  230.         }
  231.     }
  232.  
  233.     # Establish a target near Indy at f_XDist, f_Ydist, f_ZDist
  234.     # Fill in offsets as needed.  0.1 = 1m
  235.     # Positive values are right (x) and forward (y) of thing center
  236.     # Z values are offset from thing center (itself offset from insert point)
  237.     # The mysterious zero vector parm in CreateThingAtPos() is for PYR
  238.     # xdist (defined above) is one half of block height, plus one
  239.  
  240.     # Create an invisible box above Indy.  (used in "Touched" section)
  241.  
  242.     if (bSurfaceFound)
  243.     {
  244.         v_modvec = VectorSet(f_XDist, f_YDist, f_ZDist);
  245.         v_targetpos = VectorAdd(VectorTransformToOrient(player, v_modvec), GetThingPos(player));    
  246.         targetsector = FindNewSectorFromThing(player, v_targetpos);
  247.         if (invisiBox != -1)
  248.         {
  249.             DetachThing(invisiBox);
  250.             DestroyThing(invisiBox);
  251.         }
  252.         invisiBox = CreateThingAtPos(boxTpl, targetsector, v_targetpos, '0 0 0');
  253.         CaptureThing(invisiBox); # no capture, no work
  254.         AttachThingToThing(invisiBox, player); # track his move
  255.     }
  256.  
  257.     if ((GetSenderID() == 1)&& ((GetSenderRef() != triggerFace) || (GetSenderRef() != retractFace)))
  258.     {
  259.         hanging = 1;
  260.     }
  261.     return;
  262.  
  263. # ========================================================================================
  264. exited:
  265.  
  266.     # Destroy the invisible box created when Indy was hanging.
  267.  
  268.     bSurfaceFound = 0;
  269.  
  270.     for (currentSurface = 0; (currentSurface < 5) && !bSurfaceFound; currentSurface = currentSurface + 1)
  271.         if (GetSenderRef() == hangR0[currentSurface])
  272.             bSurfaceFound = 1;
  273.  
  274.     if (!bSurfaceFound)
  275.         for (currentSurface = 0; (currentSurface < 6) && !bSurfaceFound; currentSurface = currentSurface + 1)
  276.             if (GetSenderRef() == hangL0[currentSurface])
  277.                 bSurfaceFound = 1;
  278.  
  279.     if (bSurfaceFound && invisiBox != -1)
  280.     {
  281.         DetachThing(invisiBox);
  282.         DestroyThing(invisiBox);
  283.         invisiBox = -1;
  284.     }
  285.  
  286.     if ((GetSenderID() == 1) && (hanging == 1))
  287.     {
  288.         hanging=0;
  289.     }
  290.  
  291. return;
  292.  
  293. # ........................................................................................
  294. pulse:
  295.  
  296.     # Move each block out
  297.     counter = counter + 1;
  298.     SetThingFlags(fakeBlock0[counter], 0x80000);
  299.     ClearThingFlags(block0[counter], 0x80000);
  300.     #PlaySoundThing(blocksnd, block0[counter], 1.0, 7.5, 30.0, 0);
  301.     MoveThingToPos(block0[counter], GetThingPos(blockGhost0[counter]), movespeed);
  302.     out0[counter] = 0;
  303.  
  304.     if (counter == 5)
  305.     {
  306.         SetPulse(0);
  307.         counter = 0;
  308.         retractCounter = 5;
  309.     }
  310.     return;
  311.  
  312. # ........................................................................................    
  313. arrived:
  314.  
  315.     bBlockFound=0;
  316.  
  317.     for (currentBlock = 0; (currentBlock <= 5) && !bBlockFound; currentBlock = currentBlock + 1)
  318.         if ((GetSenderRef() == Block0[currentBlock]))
  319.             bBlockFound = 1;
  320.  
  321.     if (!bBlockFound)
  322.         return;
  323.  
  324.     currentBlock = currentBlock - 1;
  325.  
  326.     # "Out" is "0" when the blocks are moving out.
  327.     if (out0[currentBlock] == 0)
  328.     {
  329.         ClearSurfaceFlags(hangR0[currentBlock], 0x1000000);
  330.         ClearSurfaceFlags(hangL0[currentBlock], 0x1000000);
  331.         ClearSurfaceFlags(hangE0[currentBlock], 0x1000000);
  332.         out0[currentBlock] = 1;
  333.                 
  334.         if (hanging == 1)
  335.         {
  336.             SetActorFlags(player, 0x200000);
  337.             DetachThing(player);
  338.         }
  339.  
  340.         if (GetSenderRef() == Block5)
  341.         {
  342.             SetTimer(autoRetract);
  343.         }
  344.  
  345.         return;
  346.     }
  347.     else
  348.     {
  349.         # "Out" is "1" when the blocks are moving back in.
  350.  
  351.         #SetThingFlags(Block0[currentBlock], 0x80000);
  352.         #ClearThingFlags(FakeBlock0[currentBlock], 0x80000);
  353.  
  354.         SetSurfaceFlags(hangR0[currentBlock], 0x1000000);
  355.         SetSurfaceFlags(hangL0[currentBlock], 0x1000000);
  356.         SetSurfaceFlags(hangE0[currentBlock], 0x1000000);
  357.         
  358.         out0[currentBlock] = 0;
  359.  
  360.         if (GetSenderRef() == Block0)
  361.         {
  362.             crosscheck = 0;
  363.         }
  364.  
  365.         return;
  366.     }
  367.  
  368.  
  369.     
  370.     #if ((hanging == 1) && (GetSenderRef() == block0[counter]))
  371.     #{
  372.     #    if (invisiBox != -1)
  373.     #    {
  374.     #        DetachThing(invisiBox);
  375.     #        DestroyThing(invisiBox);
  376.     #        invisiBox = -1;
  377.     #    }
  378.     #    SetActorFlags(player, 0x200000);
  379.     #    DetachThing(player);
  380.     #    ClearSurfaceFlags(hangR0, 0x1000000);
  381.     #    ClearSurfaceFlags(hangL0, 0x1000000);
  382.     #    ClearSurfaceFlags(hangE0, 0x1000000);
  383.     #}
  384.     
  385.     return;   
  386. # ........................................................................................
  387. timer:
  388.     # Retract all of the blocks
  389.  
  390.     if (retractCounter >= 0)
  391.     {
  392.         #PlaySoundThing(blocksnd, block0[retractCounter], 1.0, 7.5, 30.0, 0);
  393.         #MoveToFrame(block0[retractCounter], 0, autoRetractSpeed);
  394.         MoveThingToPos(block0[retractCounter], GetThingPos(backGhost0[retractCounter]), autoretractSpeed);
  395.         out0[retractCounter] = 1;
  396.         retractCounter = retractCounter - 1;
  397.         SetTimer(5.0);
  398.     }
  399.     return;
  400.  
  401. # ........................................................................................
  402. touched:    
  403.  
  404.     if (GetSourceRef() == player)
  405.         return;
  406.  
  407.     if (GetSenderRef() == invisiBox)
  408.     {
  409.         Print("Sender is invisiBox!");
  410.         SetActorFlags(player, 0x200000);
  411.         if (invisiBox != -1)
  412.         {
  413.             DetachThing(invisiBox);
  414.             DestroyThing(invisiBox);
  415.             invisiBox = -1;
  416.         }
  417.         DetachThing(player);
  418.     }
  419.  
  420.     return;
  421.     
  422. # ........................................................................................
  423. blocked:
  424. Print("blocked");
  425.  
  426. if (GetSenderRef() == block5)
  427. {
  428.     Sleep(0.5);
  429.     Print("inside blocked if statement");
  430.     MoveThingToPos(block5, GetThingPos(blockGhost5), movespeed);
  431. }
  432. if (GetSenderRef() == block4)
  433. {
  434.     Sleep(0.5);
  435.     Print("inside blocked if statement");
  436.     MoveThingToPos(block4, GetThingPos(blockGhost4), movespeed);
  437. }
  438.  
  439. return;
  440. # ........................................................................................
  441. end
  442.